﻿
namespace Demo.Web
{
  using System.Linq;
  using System.Linq.Expressions;
  using System.ServiceModel.DomainServices.Hosting;
  using System.ServiceModel.DomainServices.Server;
  using ExpressionSerialization;


  [EnableClientAccess()]
  public class TestDomainService : DomainService
  {
    
    [Invoke(HasSideEffects = true)]
    public System.Data.Linq.Binary TestSerialization(byte[] filter) //System.Data.Linq.Binary
    {
      Expression epr = ExpressionSerialization.ExpressionExtension.Deserialize(filter, typeof(Product));
      var xx = new System.Data.Linq.Binary(epr.Serialize());
      return xx; 
    }
    
    [Query(HasSideEffects = true, IsComposable = true)]
    public IQueryable<Product> GetProduct(byte[] filter) //System.Data.Linq.Binary
    {
      ProductList li = System.Web.HttpContext.Current.Session["products"] as ProductList;
      var query = from n in li select n;
      IQueryable<Product> qq = query.AsQueryable();
      //--------------------------------
      if(filter != null) {
        qq = ExpressionExtension.ApplyFilter(qq, filter);
      }
      //--------------------------------
      return qq;
    }
  }
}


